Draft
Conversation
This might happen when loading a project that no users have started yet. It seems a waste to call the API in this case
I don't like this pattern of rescuing StandardError - it means that errors in development and test are hidden. Also, since we're reporting all the errors to sentry it creates a lot of noise. In this case, it made an error that happened when listing students on a project that had none. This error happening as soon as a teacher creates a project and even in many tests but because we were rescuing it we didn't notice it. I will fix this problem in the next commit. More generally, I think we should only handle expected errors - for example, a network error is an expected error. We shouldn't try to deal with unexpected errors as we can't predict what they are or how to handle them. I've looked at sentry and the only other errors logged by this method in the last month are ones from Faraday - `BadRequestError`, `ForbiddenError`, `ServerError` and `UnauthorizedError`. I'd like to remove this rescue too eventually, but I would want to understand the Faraday errors first.
The .users and .with_users methods are intended to be called on associations, and infer the school by looking for the school in one of the projects in the association. This can lead to errors (when there are no projects with a school) or unexpected behaviour if trying to call on a scope containing different projects. By requiring the school to be passed it, it makes clear to the caller that a school is required and it only works for a single school As part of this I have fixed the related tests - some of these were passing in unexpected ways because an error was being rescued (see previous commit).
school is a method available as an association so this isn't needed
When working with this code I found it confusing as specifically returns students, not teachers that may created projects. I haven't changed the user variable in the projects controller as I think that might be other types of user.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Status
Points for consideration:
What's changed?
Description of what's been done - bullets are often best
Steps to perform after deploying to production
If the production environment requires any extra work after this PR has been deployed detail it here. This could be running a Rake task, a migration, or upgrading a Gem. That kind of thing.